<?php
/**
* @package   auto_occasion
* @subpackage entreprise
* @author    CMS
* @copyright 2011
* @license    All rights reserved
*/

class BoTypeCtrl extends jController {
    
public $pluginParams = array(
                                    '*'=>array('auth.required'=>true,
                                    'jacl2.right'=>'admin.compte.gerer'
                                    )
                            );

    /**
    * Liste des types
    */
    function index() {
        $rep = $this->getResponse('html');
        $rep->menusActifs = adminHtmlResponse::MENU_ENTREPRISE ;
        $rep->addJSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/back/js/jconfirmaction.jquery.js');
        $rep->addJSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/back/js/jconfirmaction.jquery.ask.js');


        jClasses::inc('entreprise~typeSrv');
        $liste = typeSrv::liste();

	$rep->bodyTpl = 'entreprise~BoTypeList';
	$rep->body->assign('liste', $liste);

        return $rep;
    }

    /**
    * Ajouter / Modifier un type
    */
    function editer() {
        $rep = $this->getResponse('html');
        $rep->menusActifs = adminHtmlResponse::MENU_ENTREPRISE ;


        jClasses::inc('entreprise~typeSrv');
       
        $id      = $this->param('id', '');

        $type    = ($id) ? typeSrv::chargeParId($id) : typeSrv::init();

		$rep->bodyTpl = 'entreprise~BoTypeEdit';
		
        $rep->body->assign('type', $type);

        return $rep;
    }
   
    
     /**
    * Sauvegarder un type
    */
    function sauvegarder() {
        $rep = $this->getResponse('redirect');
        
        jClasses::inc('entreprise~typeSrv');

        $type             = new stdClass();
        $type ->type_name = $this->param('libelle', '');
        $type ->type_id   = $this->param('id', '');

        if ($type ->type_id) {
            typeSrv::modifier($type );
        } else {
            typeSrv::ajouter($type );
        }
        
        $rep->action = 'entreprise~BoType:index';

        return $rep;
    }


    /**
    * Supprimer une categorie
    */
    function supprimer() {
        $rep = $this->getResponse('redirect');

        jClasses::inc('entreprise~typeSrv');
        $id = $this->intParam('id', '');
        typeSrv::supprimer($id);

        $rep->action = 'entreprise~BoType:index';

        return $rep;
    }
}

